﻿Imports System.Data.SqlClient
Imports System.Data.Odbc
Imports System.Data.OleDb


Module Rutinas
    'Dim Citra As New Citra.Herramientas

    Friend Function BuscarStrDatoNominas(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoNominas(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarDateDatoNominas(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Date

        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            ' CAMBIO: 13.11.07 ISNULL NO USADO EN VFP            cmdBuscar.CommandText = "Select IsNull(" & strCampo & ", '01/01/1900') From " & strTabla & " Where " & strWhere
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDateDatoNominas(ByVal strSqlQry As String) As Date
        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDblDatoNominas(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
           MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarDblDatoNominas(ByVal strSqlQry As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarIntDatoNominas(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoNominas(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try

            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function SetSqlNominas(ByVal strSqlQry As String) As Boolean
        Dim cnnConn As New SqlConnection
        Dim intRetVal As String
        Dim blnRetVal As Boolean

        Try

            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn
            cmdBuscar.CommandTimeout = 0

            intRetVal = cmdBuscar.ExecuteNonQuery

            blnRetVal = True

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return blnRetVal

    End Function
  
    Friend Function BuscarStrDatoInicial(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoInicial(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarDateDatoInicial(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Date

        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            ' CAMBIO: 13.11.07 ISNULL NO USADO EN VFP            cmdBuscar.CommandText = "Select IsNull(" & strCampo & ", '01/01/1900') From " & strTabla & " Where " & strWhere
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDateDatoInicial(ByVal strSqlQry As String) As Date
        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDblDatoInicial(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarDblDatoInicial(ByVal strSqlQry As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarIntDatoInicial(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoInicial(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function SetSqlInicial(ByVal strSqlQry As String) As Boolean
        Dim cnnConn As New SqlConnection
        Dim intRetVal As String
        Dim blnRetVal As Boolean

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn
            cmdBuscar.CommandTimeout = 0

            intRetVal = cmdBuscar.ExecuteNonQuery

            blnRetVal = True

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return blnRetVal

    End Function
 
    Friend Function TienePermiso(ByVal Formulario As String) As String
        Dim idUser As Integer = BuscarIntDatoInicial("Usuarios", "IdUsuario", "Nombre='" & UCase(UsuarioActivo.Trim) & "'")
        Dim idFormulario As String = BuscarIntDatoInicial("Formularios", "IdFormulario", "formulario='" & Formulario.Trim & "'")
        Dim Permiso As Integer = BuscarIntDatoInicial("PermisosUsuarios", "Permiso", "IdUsuario=" & idUser & " AND IdFormulario=" & idFormulario)
        Dim Acceso As Boolean
        If Permiso > 0 Then
            Acceso = True
        Else
            Acceso = False
        End If

        Return Acceso
    End Function
    Friend Function BuscarStrDatoCitra(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoCitra(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            Try
                strRetVal = cmdBuscar.ExecuteScalar
            Catch ex As Exception
                strRetVal = Nothing

            End Try



        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarDateDatoCitra(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Date

        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            ' CAMBIO: 13.11.07 ISNULL NO USADO EN VFP            cmdBuscar.CommandText = "Select IsNull(" & strCampo & ", '01/01/1900') From " & strTabla & " Where " & strWhere
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDateDatoCitra(ByVal strSqlQry As String) As Date
        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDblDatoCitra(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")

        Finally

            'Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Dispose()
                cnnConn.Close()
                SqlConnection.ClearAllPools()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarDblDatoCitra(ByVal strSqlQry As String) As Double
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Double

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            If Not IsDBNull(cmdBuscar.ExecuteScalar) Then
                intRetVal = cmdBuscar.ExecuteScalar
            Else
                intRetVal = 0
            End If


        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Dispose()
                cnnConn.Close()
                SqlConnection.ClearAllPools()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoCitra(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally

            'Finally
            'If cnnConn.State = ConnectionState.Open Then
            'cnnConn.Close()
            'End If
        End Try

        cnnConn.Close()
        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoCitra(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            If Not IsDBNull(cmdBuscar.ExecuteScalar) Then
                intRetVal = cmdBuscar.ExecuteScalar
            Else
                intRetVal = 0
            End If


        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally

            'Finally
            'If cnnConn.State = ConnectionState.Open Then
            'cnnConn.Close()
            'End If
        End Try

        cnnConn.Close()
        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function
    Friend Function SetSqlCitra(ByVal strSqlQry As String) As Boolean
        Dim cnnConn As New SqlConnection
        Dim intRetVal As String
        Dim blnRetVal As Boolean

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn
            cmdBuscar.CommandTimeout = 0

            intRetVal = cmdBuscar.ExecuteNonQuery

            blnRetVal = True

        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return blnRetVal

    End Function
   
    Friend Function BuscarIntDatoNOI(ByVal strSqlQry As String) As String
        Dim cnnConn As New OdbcConnection
        Dim intRetVal As Integer

        Try

            cnnConn.ConnectionString = NoiConnection
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            If Not IsDBNull(cmdBuscar.ExecuteScalar) Then
                intRetVal = cmdBuscar.ExecuteScalar
            Else
                intRetVal = 0
            End If


        Catch ex As SqlException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally

            'Finally
            'If cnnConn.State = ConnectionState.Open Then
            'cnnConn.Close()
            'End If
        End Try

        cnnConn.Close()
        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function
    Friend Function BuscarStrDatoNOI(ByVal strSqlQry As String) As String
        Dim cnnConn As New OdbcConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = NoiConnection
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OdbcException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function
    Friend Function BuscarStrDatoSAE(ByVal strSqlQry As String) As String
        Dim cnnConn As New OdbcConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = SAEConnection
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OdbcException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function
   
   
    Friend Function BuscarDateDatoNOI(ByVal strSqlQry As String) As Date
        Dim cnnConn As New OdbcConnection
        Dim dRetVal As Date

        Try
            cnnConn.ConnectionString = NoiConnection
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OdbcException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function
    Friend Function BuscarDblDatoNOI(ByVal strSqlQry As String) As Double
        Dim cnnConn As New OdbcConnection
        Dim intRetVal As Double

        Try

            cnnConn.ConnectionString = NoiConnection
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            If Not IsDBNull(cmdBuscar.ExecuteScalar) Then
                intRetVal = cmdBuscar.ExecuteScalar
            Else
                intRetVal = 0
            End If


        Catch ex As OdbcException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Dispose()
                cnnConn.Close()
                SqlConnection.ClearAllPools()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function
    Friend Function BuscarDblDatoSAE(ByVal strSqlQry As String) As Double
        Dim cnnConn As New OdbcConnection
        Dim intRetVal As Double

        Try

            cnnConn.ConnectionString = SAEConnection
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            If Not IsDBNull(cmdBuscar.ExecuteScalar) Then
                intRetVal = cmdBuscar.ExecuteScalar
            Else
                intRetVal = 0
            End If


        Catch ex As OdbcException
            MsgBox(ex.Message, MsgBoxStyle.Information, "Mensaje de la BD")
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Dispose()
                cnnConn.Close()
                SqlConnection.ClearAllPools()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function
    Friend Function BuscarIntDatoBiometria(ByVal strSqlQry As String) As String
        Dim cnnConn As New OleDbConnection
        Dim intRetVal As Integer

        Try

            cnnConn.ConnectionString = BiometriaConnection
            cnnConn.Open()

            Dim cmdBuscar As New OleDbCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OleDbException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function
    Friend Function BuscarStrDatoBiometria(ByVal strSqlQry As String) As String
        Dim cnnConn As New OleDbConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = BiometriaConnection
            cnnConn.Open()

            Dim cmdBuscar As New OleDbCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OleDbException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function
    Enum OrigenUbicacion As Integer
        CatalogoArticulos = 1
        MenuPricipal = 2
        CatalogoProductos = 3
        Favoritos = 4
    End Enum
End Module
